package com.homework;

import java.io.File;
import java.util.Scanner;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/3/28 18:35
 * @description
 */
public class T5 {
    static int dot = 0;
    static int java = 0;
    static int txt = 0;
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入文件夹路径：");
        String Path = input.nextLine();
        File dir = new File(Path);
//        File dir = new File("D:\\file\\test");
        typeCount(dir);

        System.out.println("docx类型的文件有 " + dot+"个");
        System.out.println("java的类型的文件有 " + java+"个");
        System.out.println("txt的类型的文件有 " + txt+"个");
    }

    public static void typeCount(File dir) {
        File[] files = dir.listFiles();
        for (File file : files) {

            if (file.isDirectory()) {
                typeCount(file);
            }else {
//                System.out.println(file);
                String fileName = file.getName();
//                System.out.println("fileName = " + fileName);
                String type = fileName.substring(fileName.indexOf('.')+1);
//                System.out.println("type = " + type);
                switch (type){
                    case "docx":
                        dot++;
                        break;
                    case "java":
                        java++;
                        break;
                    case "txt":
                        txt++;
                        break;
                }
            }
        }
    }
}
